package com.qf.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.qf.json.MySerializer;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 用户对象
 */
public class User {


    //  {new_id:123 }
    @JsonProperty("new_id") //起别名
    private Integer id;
    private String name;
    @JsonIgnore  //忽略
    private Boolean gender;
    
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    //@JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date birth;

    // null 值  空串  长度是0  不要输出
    @JsonInclude(value= JsonInclude.Include.NON_EMPTY)
    private String[] hobby;
    //集合类型
    //null 值  不要输出
    @JsonInclude(value= JsonInclude.Include.NON_NULL)
    private List<User> users;


    /**
     * salary : 薪水
     *
     * 18000.126 ： 将薪水在转成JSON串的时候 能不能四舍五入
     *
     * @JsonSerialize:自定义JSON转换规则
     *
     */
    @JsonSerialize(using = MySerializer.class)
    private Double salary = 18000.126;//在输出此属性时，使用MySerializer输出



    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getGender() {
        return gender;
    }

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public String[] getHobby() {
        return hobby;
    }

    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", gender=" + gender +
                ", birth=" + birth +
                ", hobby=" + Arrays.toString(hobby) +
                '}';
    }
}